package com.hardson.toolkit.listcomparator;

import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;

public class ChineseListComparator<T> extends ListComparator<T> {

	/**
	 * 中文按拼音排序
	 */
	private final static Comparator<Object> CHINA_COMPARE = Collator.getInstance(Locale.CHINA);

	public ChineseListComparator() {
	}

	@Deprecated
	public ChineseListComparator(final String colName, final Class<T> clazz, final int order) {
		this.colName = colName;
		this.cl = clazz;
		this.order = order;
	}

	public ChineseListComparator(final String colName, final int order) {
		this.colName = colName;
		this.order = order;
	}

	@Override
	public int compare(final T t1, final T t2) {
		T swapObj[] = this.swap(t1, t2);
		Object val0 = this.getValueObj(swapObj[0]);
		Object val1 = this.getValueObj(swapObj[1]);
		Integer result = this.compareNull(val0, val1);
		if (result != null) {
			return result;
		}
		String cmp1 = val0.toString();
		String cmp2 = val1.toString();
		return CHINA_COMPARE.compare(cmp1, cmp2);
		// return cmp1.compareTo(cmp2);
	}
}
